#include "NormalNode.h"

#include <QDebug>

#include <math.h>

NormalNode::NormalNode(Node *mean, Node *variance, double sampleValue, bool isObserved, QString label) :
    Node(NORMAL, sampleValue, isObserved, label),
    mean(mean),
    variance(variance)
{
    mean->addChild(this);
    variance->addChild(this);
}

NormalNode::NormalNode(const NormalNode& other) :
    Node(other),
    mean(other.mean),
    variance(other.variance)
{

}

NormalNode::~NormalNode()
{

}

double NormalNode::randomSample()
{
    return Distribution::sharedInstance()->randomNormal(mean->getLastSample(), sqrt(variance->getLastSample()));
}

double NormalNode::logLikelihood(double x)
{
    return log(Distribution::sharedInstance()->likelihoodNormal(x, mean->getLastSample(), sqrt(variance->getLastSample())));
}


